package ff.ii.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Admin on 12/27 0027.
 */
public class PasswordFilter implements Filter {
    private FilterConfig filterConfig;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig=filterConfig;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request= (HttpServletRequest) servletRequest;
//        HttpServletResponse response= (HttpServletResponse) servletResponse;
        String initPassword=filterConfig.getServletContext().getInitParameter("password");
        String password =request.getParameter("password");
        if(! initPassword.equals(password)){
            request.setAttribute("message","密码错误,请重新输入!");
            request.getRequestDispatcher("/filter/login.jsp").forward(request,response);
        }
        filterChain.doFilter(request,response);

    }

    @Override
    public void destroy() {

    }
}
